package com.cat.math;

import java.util.ArrayList;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/prime-subtraction-operation/
 * @create 2025/10/16 16:04
 * @since JDK17
 */

public class Solution11 {
    static int N = 1010;
    static boolean[] isPrime = new boolean[N];
    static ArrayList<Integer> list = new ArrayList<>();
    static {
        isPrime[0] = isPrime[1] = true;
        for (int i = 2; i < N; i++) {
            if (!isPrime[i]) {
                list.add(i);
                for (long j = (long) i * i; j < N; j += i ) {
                    isPrime[(int) j] = true;
                }
            }
        }
    }
    public boolean primeSubOperation(int[] nums) {
        int last = -1, cur = 0, n = nums.length;
        for (int i = 0; i < n; i++) {
            cur = nums[i];
            for (int p : list) {    //
                if (nums[i] - p <= last || nums[i] <= p) {
                    break;
                }
                cur = nums[i] - p;
            }
            if (cur <= last) {
                return false;
            }
            nums[i] = cur;
            last = nums[i];
        }

        return true;
    }
}
